package listeners;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import beans.Pizza;

import dao.DAO;
import dao.DAOFactory;

/**
 * Application Lifecycle Listener implementation class ContextListener
 *
 */
@WebListener
public class ContextListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public ContextListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent sce) {
        DAO<Pizza> pizzaDAO = DAOFactory.getDAOPizza();
        ServletContext context = sce.getServletContext();
        context.setAttribute("pizzaDAO", pizzaDAO);
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce) {
    	 ServletContext context = sce.getServletContext();
         context.removeAttribute("pizzaDAO");
    }
	
}
